import store from '@/store';

export default {
  inserted(el, binding, vNode) {
    // 1. 获取传递过来的参数
    // 2. 和仓库比较
    // 3. 操作dom 让它没

    let {value} = binding;
    let roles = value;
    if (!Array.isArray(roles)) {
      throw new Error("you can not parse this pamers should be like this v-permission='['admin']'")
    }
    // 角色
    let role = store.state.users.router_id;
    let hasIndex = roles.indexOf(role);
    if (hasIndex === -1) {
      // 删
      el.parentNode && el.parentNode.removeChild(el);
    }
  },
  binding() {
  }
}
